<template>
  <!-- 详情页面 -->
  <div>
    <div v-for="item in photoinfo" :key="item.id" class="photoinfo">
      <p class="p1">{{item.title}}</p>
      <span class="p2">发表时间：{{item.add_time | dataFormat}}</span>
      <span class="p3">点击次数：{{item.click}}</span>
      <div class="clear"></div>
      <hr>
      <!-- 缩略图      安装npm i vue-preview -S-->
      <div class="pic">
        <!-- 适应于2.0以上 -->
        <vue-preview :slides="list"></vue-preview>
      </div>
      <div class="clear"></div>
      <div v-html="item.content" style="margin:10px"></div>
    </div>
    <!-- 引入写过的评论组件 -->
    <comments :id="this.id"></comments>
  </div>
</template>
<script>
import comments from "../homexinwen/comments.vue"; //评论组件
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id, //路由参数
      photoinfo: [], //内容列表
      list: [] //缩略图
    };
  },
  created() {
    this.getphotoinfo();
    this.getpreviews();
  },
  methods: {
    getphotoinfo() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimageInfo/" + this.id)
        .then(result => {
          var result = result.body;
          if (result.status == 0) {
            this.photoinfo = result.message;
          } else {
            Toast("加载失败");
          }
        });
    },
    getpreviews() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getthumimages/" + this.id)
        .then(result => {
          var result = result.body;
          // console.log(result);
          if (result.status == 0) {
            result.message.forEach(item => {
              // 缩略图必须的条件
              item.w = 600;
              item.h = 400;
              item.msrc = item.src; //重要的转换 新版本的需要
            });
            this.list = result.message;
          } else {
            Toast("加载失败");
          }
        });
    }
  },
  components: {
    comments //评论组件
  }
};
</script>
<style scoped>
.clear {
  clear: both;
}
.photoinfo .p1 {
  text-align: center;
  color: #3399ff;
  font-size: 15px;
  font-weight: 600;
  height: 50px;
  /* line-height: 50px; */
  margin-top: 20px;
  padding: 5px;
}
.photoinfo .p2 {
  float: left;
  font-size: 14px;
  color: #999999;
  margin: 5px;
}
.photoinfo .p3 {
  float: right;
  font-size: 14px;
  color: #999999;
  margin: 5px;
}
hr {
  color: #999999;
  margin: 5px;
}
</style>
